#!/bin/zsh

#function t_teardown {
  emulate -L zsh
  setopt local_options

  # Return to project directory
  popd

  # reset current session
  HOME=$T_PREV_HOME
  ZDOTDIR=$T_PREV_ZDOTDIR

  # unfunction all antidote
  for fn in ${(k)functions}; do
    [[ $fn == *antidote* ]] && unfunction -- $fn
  done
  (( $+functions[git] )) && unfunction git

  # unfunction zsh-defer
  (( $+functions[zsh-defer] )) && unfunction zsh-defer

  # restore original path/fpath
  path=( $T_PREV_PATH )
  fpath=( $T_PREV_FPATH )

  # restore original zstyles
  source <(zstyle -L ':antidote:*' | awk '{print "zstyle -d",$2}')
  source <(printf '%s\n' $T_PREV_ZSTYLES)

  # remove tempdir
  [[ -d "$T_TEMPDIR" ]] && command rm -rf -- "$T_TEMPDIR"

  # remove vars
  for var in \
    ANTIDOTE_HOME \
    T_TEMPDIR \
    T_PREV_HOME \
    T_PREV_ZDOTDIR \
    T_PREV_PATH \
    T_PREV_FPATH \
    plugins \
    libs
  do
    [[ -v $var ]] && unset $var
  done
#}
